-- @owner: @zhangbingliang
-- @date: 2025-07-31
-- @testpoint: fetch next正向遍历后使用fetch_status函数
-- @modify: modified by @zhangbingliang at 2025-07-31

--prestep1:连接到D库
@conn PrimaryDbDmode;

--step1:建表;expect:成功
drop table if exists t_fetch0001;
CREATE TABLE t_fetch0001 (
ID INT PRIMARY KEY,
Value NVARCHAR(50)
);

INSERT INTO t_fetch0001 VALUES (1, 'A'), (2, 'B'), (3, 'C');

--step2:定义游标，并使用FETCH NEXT遍历结果集;expect:成功，fecth_status前三次返回0，最后一次返回-1
begin; /
DECLARE c_fetch0001 CURSOR FOR SELECT ID, Value FROM t_fetch0001 ORDER BY ID; /
FETCH NEXT FROM c_fetch0001;
select @@FETCH_STATUS;

FETCH NEXT FROM c_fetch0001;
select @@FETCH_STATUS;

FETCH NEXT FROM c_fetch0001;
select @@FETCH_STATUS;

FETCH NEXT FROM c_fetch0001;
select @@FETCH_STATUS;
close c_fetch0001;
end;

--step3:清理环境;expect:成功
drop table if exists t_fetch0001;